import { RosterInterface } from '@/api/interface/personnel/roster/roster';
import { BasicForm } from '@/components/ProForm/interface';
import { PublicInterface } from '@/interface/public';

/**
 * 人员切换类型
 */

export function useChangeTypeForm(proTableBox: PublicInterface.ProTableValue) {
  let changeTypeForm = reactive<BasicForm<RosterInterface.ReqRosterChangeType>>({
    form: {
      type: '',
      id: null
    },
    title: '',
    minWidth: 660,
    labelWidth: [100, 120],
    visible: false,
    formAttrs: {
      labelWidth: '120px'
    },
    transitionArr: [
      {
        oldField: 'employeeType',
        newField: 'type'
      }
    ],
    options: [
      {
        type: 'input',
        label: 'ID',
        prop: 'id',
        hide: true
      },
      {
        type: 'select',
        hide: false,
        prop: 'type',
        label: '切换类型',
        rules: [
          {
            required: true,
            message: '切换类型',
            trigger: 'change'
          }
        ],
        children: []
      }
    ]
  });

  /**
   * @description: 保存表单数据
   * @return {*}
   */
  const saveAddChangeTypeForm = async form => {
    await rosterChangeType(form);
    changeTypeForm.visible = false;
    elMessage();
    proTableBox.value?.getTableList();
  };

  return { changeTypeForm, saveAddChangeTypeForm };
}
